<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>es6 Let和var</title>
</head>

<body>
    <h1>es6 Let</h1>
    <script>
        // for (let i = 0; i < 5; i++) {
        //     setTimeout(() => {
        //         console.log(i) // 0 1 2 3 4 
        //     }, 1000)
        // }
        // console.log(i)  // undefined

        for (var i = 0; i < 5; i++) {
            setTimeout(() => {
                console.log(i) // 5 5 5 5 5
            }, 1000)
        }
        console.log(i)  // 5
    </script>
</body>

</html>